package cn.mw.cmdb.entity.graph;

import cn.mw.cmdb.entity.modelRelation.ModelRelationDTO;
import cn.mw.cmdb.entity.modelRelation.ModelRelationInfo;
import cn.mw.microMonitorCommon.util.ListMapObjUtils;
import lombok.Data;

import java.util.Map;
import java.util.Objects;

@Data
public class ComboParam {
    private String id;
    private String label;
    private int weight;

    public ComboParam(){
    }

    public ComboParam(String id, String label, int weight) {
        this.id = id;
        this.label = label;
        this.weight = weight;
    }

    public void extractFrom(Map<String, ModelRelationDTO> modelAssetMap) throws Exception {
        ModelRelationDTO modelRelationDTO = modelAssetMap.get(this.id);
        if (null != modelRelationDTO) {
            Map map = (Map) modelRelationDTO.getRelationInfoMap().get(this.id);
            ModelRelationInfo modelRelationInfo = ListMapObjUtils.mapToBean(map, ModelRelationInfo.class);
            this.label = modelRelationInfo.getRelationName();
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ComboParam that = (ComboParam) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
